#include "Stack.h"
#include <iostream>
template <class C>
Stack<C>::Stack()
{
	this -> length = 20;
	this -> p = new C[length];
	this -> index = -1;
	std::cout << "The implicit ctor was called.";
}
template <class C>
Stack<C>::Stack(int length)
{
	this -> length = length;
	this -> p = new C[length];
	this -> index = -1;
}
template <class C>
Stack<C>::~Stack()
{
	delete p;
	std::cout << "\nThe stack was destroyed.";
}
template <class C>
void Stack<C>::push(C element)
{
	if (this -> full())
		std::cout << "The stack is full.";
	else
	{
		++index;
		p[index] = element;
	}
}
template <class C>
C Stack<C>::pop()
{
	C temp = p[index];
	--index;
	return temp;
}
template <class C>
int Stack<C>::getTotalNumber()
{
	return index + 1;
}
template <class C>
void Stack<C>::sort()
{
	int i, j, aux;
	for (i = 1; i <= index; ++i)
	{
		aux = this -> p[i];
		j = i - 1;
		while (j >= 0 && aux < this -> p[j])
		{
			this -> p[j + 1] = this -> p[j];
			--j;
		}
		this -> p[j + 1] = aux;
	}
}
template <class C>
void Stack<C>::print()
{
	if (this -> empty())
		std::cout << "The stack is empty.";
	else
	{
		std::cout << "\nThese are the elements from the stack:\n";
		for (int i = 0; i <= this -> index; ++i)
			std::cout << p[i] << " ";
	}
}
template <class C>
bool Stack<C>::empty()
{
	if (this -> index == -1)
		return true;
	else
		return false;
}
template <class C>
bool Stack<C>::full()
{
	if (this -> index == this -> length)
		return true;
	else
		return false;
}